-- UnrealStatue
-- Created by huanghr Mar/24/2016
-- 你的雕像

-- 初始化
function initUnrealStatue(self)
    self.item:removeAllChildren();

    local pos = self.gridData:getPos();
    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            -- 更新建筑访问
            AudioM.playFx("ui_open1");
            self:updateBuildingVisit();

            if self.gridData.isTaken == nil then
                local function okFunc()
                    if self.gridData.state == GRID_STATE_DISABLE then
                        -- 已经失效，不处理
                        return;
                    end

                    self.gridData.isTaken = 1;

                    -- 奖励
                    local bonus = DungeonActionM.go("do_unreal_statue_bonus", pos);
                    if bonus == false then bonus = {}; end

                    -- 特效
                    self:playBonusListEffect(bonus, false);
                end
                self:openBuildingView(okFunc);
            else
                self:openBuildingView(nil, nil, nil, buildingInfo["view_text2"]);
            end

        end
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end
